package cn.itsource.zcn.org.service.impl;

import cn.itsource.zcn.org.domain.Shop;
import cn.itsource.zcn.org.mapper.EmployeeMapper;
import cn.itsource.zcn.org.mapper.ShopMapper;
import cn.itsource.zcn.org.query.DepartmentQuery;
import cn.itsource.zcn.org.query.ShopQuery;
import cn.itsource.zcn.org.service.IShopService;
import cn.itsource.zcn.utils.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


import java.util.Date;
import java.util.List;

/**
 * (Shop)表服务实现类
 *
 * @author makejava
 * @since 2021-08-13 19:46:50
 */
@Service
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class ShopServiceImpl implements IShopService {
    @Autowired
    private ShopMapper tShopMapper;
    @Autowired
    private EmployeeMapper employeeMapper;


    /**
     * 新增数据
     *
     * @param tShop 实例对象
     */
    @Override
    @Transactional
    public void save(Shop tShop) {
        tShop.setState(0);
        tShop.setRegisterTime(new Date());
        tShop.getAdmin().setState(0);
        employeeMapper.save(tShop.getAdmin());
        tShopMapper.save(tShop);
    }

    /**
     * 修改数据
     *
     * @param tShop 实例对象
     */
    @Override
    @Transactional
    public void update(Shop tShop) {
        tShopMapper.update(tShop);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     */
    @Override
    @Transactional
    public void delete(Long id) {
        tShopMapper.delete(id);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Shop queryById(Long id) {
        return tShopMapper.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @return 对象列表
     */
    @Override
    public List<Shop> queryAll() {
        return tShopMapper.queryAll();
    }

    @Override
    public QueryResult queryPage(ShopQuery shopQuery) {
        Integer count = tShopMapper.count(shopQuery);
        List<Shop> page = tShopMapper.page(shopQuery);

        return new QueryResult(page,count);
    }

    @Override
    public void deleteBatch(Long[] ids) {

    }


}
